<template>
  <div class="orders-list">
    <el-card class="box-card">
      <el-form ref="searchFormRef" :model="params" inline>
        <el-form-item label="用户ID:">
          <el-input style="width:80px;" v-model="params.user_id"></el-input>
        </el-form-item>
        <el-form-item label="支付状态:">
          <el-input style="width:80px;" v-model="params.pay_status"></el-input>
        </el-form-item>
        <el-form-item label="是否发货:">
          <el-input style="width:80px;" v-model="params.is_send"></el-input>
        </el-form-item>
        <el-form-item label="发票抬头:">
          <el-input
            style="width:80px;"
            v-model="params.order_fapiao_title"
          ></el-input>
        </el-form-item>
        <el-form-item label="公司名称:">
          <el-input
            style="width:148px;"
            v-model="params.order_fapiao_company"
          ></el-input>
        </el-form-item>
        <el-form-item label="发货地址:">
          <el-input
            style="width:150px;"
            v-model="params.consignee_addr"
          ></el-input>
        </el-form-item>
        <el-form-item style="margin-left:30px;">
          <el-button-group>
            <el-button
              style="width:100px;"
              type="primary"
              icon="el-icon-search"
              @click="clickSearch"
              >搜素</el-button
            >
          </el-button-group>
        </el-form-item>
      </el-form>

      <el-table
        :data="tableData"
        border
        style="width: 100%"
        :header-cell-style="{ textAlign: 'center' }"
        :cell-style="{ textAlign: 'center' }"
        max-height="500px"
      >
        <el-table-column label="#" width="80" type="index"> </el-table-column>
        <el-table-column prop="order_id" label="商品 ID" width="100" sortable>
        </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="200">
        </el-table-column>
        <el-table-column prop="order_fapiao_title" label="发票抬头" width="100">
        </el-table-column>
        <el-table-column prop="user_id" label="用户 ID" width="80">
        </el-table-column>
        <el-table-column
          prop="pay_status"
          label="订单状态"
          width="110"
          sortable
        >
          <template v-slot="{ row }">
            <el-tag type="danger" v-if="row.pay_status === '0'">
              未付款
            </el-tag>
            <el-tag type="success" v-else-if="row.pay_status === '1'">
              已付款
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" sortable width="110">
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="创建时间"
          width="160"
          sortable
        >
          <template v-slot="{ row }">
            {{ row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="修改时间"
          width="160"
          sortable
        >
          <template v-slot="{ row }">
            {{ row.update_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column prop="order_price" label="总金额" width="100" sortable>
        </el-table-column>
        <el-table-column prop="order_pay" label="支付方式" width="120" sortable>
          <template v-slot="{ row }">
            <el-tag type="danger" v-if="row.order_pay === '0'">
              未付款
            </el-tag>
            <el-tag v-else-if="row.order_pay === '1'">
              已付款
            </el-tag>
            <el-tag type="success" v-else-if="row.order_pay === '2'">
              已付款
            </el-tag>
            <el-tag type="warning" v-else-if="row.order_pay === '3'">
              已付款
            </el-tag>
          </template>
          <!-- 0未支付 1支付宝  2微信  3银行卡 -->
        </el-table-column>
        <el-table-column label="操作" width="280px" fixed="right">
          <template v-slot="{ row }">
            <el-button
              type="primary"
              icon="el-icon-edit"
              @click="openAddressDialog(row)"
              >修改地址</el-button
            >
            <el-button type="success" icon="el-icon-location"
              >物流信息</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <Pagination
        :total="total"
        :page.sync="params.pagenum"
        :limit.sync="params.pagesize"
        @pagination="getOrdersList"
      />
    </el-card>
    <!-- 修改收货地址 -->
    <el-dialog
      title="收货地址"
      :visible.sync="dialogChangeAddress"
      :append-to-body="true"
    >
      <el-form :model="addressForm" ref="addressFormRef">
        <el-form-item label="省市区/县" :label-width="formLabelWidth">
          <el-cascader
            v-model="addressForm.cityValue"
            :options="cityList"
            :props="cityProps"
            style="width:500px;"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" :label-width="formLabelWidth">
          <el-input
            v-model="addressForm.detailValue"
            autocomplete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogChangeAddress = false">取 消</el-button>
        <el-button type="primary" @click="submitAddress">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import cityList from '@/utils/citydata'
import { getOrdersList } from '@/api/order'
export default {
  name: 'Orderslist',
  components: {
    Pagination
  },
  props: {},
  data() {
    return {
      params: {
        query: '',
        pagenum: 1,
        pagesize: 10,
        user_id: '',
        pay_status: '',
        is_send: '',
        order_fapiao_title: '',
        order_fapiao_company: '',
        order_fapiao_content: '',
        consignee_addr: ''
      },
      tableData: [],
      total: 0,
      dialogChangeAddress: false, // 修改收货地址
      addressForm: {
        cityValue: '',
        detailValue: ''
      },
      formLabelWidth: '120px',
      cityValue: [],
      cityList, // 城市列表
      cityProps: {
        expandTrigger: 'hover',
        value: 'value',
        label: 'label',
        children: 'children'
      },
      changeItem: {} // 需要修改地址的
    }
  },
  methods: {
    clickSearch() {
      this.params.pagenum = 1
      this.getOrdersList()
    },
    openAddressDialog(item) {
      this.changeItem = item
      this.dialogChangeAddress = true
    },
    submitAddress() {},
    async getOrdersList() {
      const { data: res } = await getOrdersList(this.params)
      console.log(res)
      this.tableData = res.goods
      this.total = res.total
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getOrdersList()
  }
}
</script>
<style lang="scss" scoped></style>
